#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
typedef int  HpDateType;
typedef struct HpeeNode
{
	HpDateType* a;
	int sz;
	int capacity;
}Hp;

void Dhinit(Hp* p)
{
	p->a = NULL;
	p->sz = 0;
	p->capacity = 0;
}

void AdjustDwon(HpDateType* a, int child)
{
	int parent = (child - 1) / 2;
	while (parent>=0)
	{
		if (a[parent] > a[child])
		{
			HpDateType tmp = a[parent];
			a[parent] = a[child];
			a[child] = tmp;
		}
		else
		{
			break;
		}
		child = parent;
		parent = (child - 1) / 2;
	}
}

void DhPush(Hp* p, HpDateType x)
{
	if (p->sz == p->capacity)
	{
		int newnode = p->capacity == 0 ? 4 : p->capacity * 2;
		HpDateType* tmp = realloc(p->a, sizeof(HpDateType) * newnode);
		if (!tmp)
		{
			perror("realloc file");
			return ;
		}
		p->a = tmp;
		p->capacity = newnode;
	}
	p->a[p->sz] = x;
	p->sz++;
	AdjustDwon(p->a, p->sz - 1);
}


int main()
{
	int arr[] = { 65,100,70,32,50,60 };
	int sz = sizeof(arr) / sizeof(*arr);
	int i = 0;
	Hp head;
	Dhinit(&head);
	for (i = 0; i < sz; i++)
	{
		DhPush(&head, arr[i]);
	}

	system("pause");
}